package com.stoneframe.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.stoneframe.util.baseApp.Const;
import com.stoneframe.util.baseApp.PageData;

public class LoginHandlerInterceptor extends HandlerInterceptorAdapter {

	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		// TODO Auto-generated method stub
		String path=request.getServletPath();
		if(path.matches(Const.NoLoginPath)){
			return true;
		}else{
			Subject currentUser = SecurityUtils.getSubject();  
			Session session = currentUser.getSession();
			PageData user = (PageData)session.getAttribute(Const.SessionUser);
			if(user!=null&&!user.isEmpty()){
				return true;
			}else{
				//登陆过滤
//				response.sendRedirect(request.getContextPath() + Const.Login);
//				return false;		
				return true;
			}
		}
	}
	
	

}
